<?php

class SiteController extends Controller
{
    public function filters()
    {
        $parent_filters = parent::filters();
        // $parent_filters[] = 'filterFunction';
        return $parent_filters;
    }

    public function actionIndex()
    {
        $this->actionLang();
        $this->pageTitle = Yii::t('layout', 'MAIN_TITLE');
        $this->pageKeywords = '';
        $this->pageDescription = '';

        $this->render('index');
    }

    public function actionError()
    {
        $this->pageTitle = Yii::t('layout', 'MAIN_TITLE');
        $this->pageKeywords = '';
        $this->pageDescription = '';

        /** @var $errHandler CErrorHandler */
        $errHandler = Yii::app()->errorHandler;
        if ($error = $errHandler->getError()) {
            if ($error['type'] == 'CustomHttpException') {
                if (Yii::app()->request->isAjaxRequest) {
                    echo $error['message'];
                } else {
                    $this->render(
                        'custom_error',
                        array(
                            'error' => $error,
                        )
                    );
                }
            } else {
                $conf_arr = AutoloadDbConfig::init();
                if (Yii::app()->request->isAjaxRequest) {
                    echo $error['message'];
                } else {
                    $this->render(
                        'error',
                        array(
                            'error' => $error,
                            'conf_arr' => $conf_arr,
                        )
                    );
                }
            }
        }
    }

    public function actionLang()
    {
        //$new_lang = strtolower(Yii::app()->request->getPost('lang'));
        $new_lang = 'en';
        if($new_lang){
            Yii::app()->language = $new_lang;
            setcookie('lang', $new_lang, 0x6FFFFFFF, '/');
        }
    }

    public function actionUnderConstruction()
    {
        $this->render('under_construction');
    }

    /*public function actionPleaseLogin()
    {
        $this->render('please_login');
    }*/

    /*public function actionPassActivate()
    {
        $this->pageTitle = Yii::t('site_passactivate', 'PAGE_TITLE');
        $this->pageKeywords = '';
        $this->pageDescription = '';
        $request = Yii::app()->request;
        $message = Yii::t('site_passactivate', 'SUCCESS');
        $key = $request->getQuery('key', false);

        if ($key === false || $key == '0') {
            $message = Yii::t('site_passactivate', 'E_PARAMS');
            $this->render('passactivate', array('message' => $message));
            exit;
        }

        $user_model = new User();
        $user = $user_model->getUserWithKey($key);
        if (isset($user['email']))
        {
            $new_pass = Generate::randomStr(6);
            $user_model->setNewPassword($user['email'], $new_pass);
            Notifier::newPasswordEmailNotify($user['email'], $new_pass);
            $user_model->updateColumnByEmail('passactivate', 0, $user['email']);

        } else {
            $message = Yii::t('site_passactivate', 'E_KEYNOTFOUND');
            $this->render('passactivate', array('message' => $message));
            exit;
        }

        $this->render('passactivate', array('message' => $message));
    }*/
}
